package com.example.park_2306


import android.webkit.JavascriptInterface
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.base.mvi.BaseViewActivity
import com.example.park_2306.databinding.ActivityWebViewBinding
import com.tencent.smtt.sdk.WebChromeClient
import com.tencent.smtt.sdk.WebView
import com.tencent.smtt.sdk.WebViewClient

@Route(path = "/app/WebViewActivity")
class WebViewActivity : BaseViewActivity<ActivityWebViewBinding>() {
    override fun getLayout(): Int = R.layout.activity_web_view

    override fun initView() {

        binding.wv.apply {
            //loadUrl("http://www.baidu.com")//添加外网路径
            loadUrl("file:///android_asset/test.html")//添加本地文件
            webViewClient = WebViewClient()//在app内部打开
            webChromeClient = object : WebChromeClient(){
                override fun onProgressChanged(p0: WebView?, p1: Int) {
                    super.onProgressChanged(p0, p1)
                    if(p1==100){
                        binding.pb.isVisible = false
                    }
                    binding.pb.progress = p1
                }
            }
            settings.javaScriptEnabled = true//允许和js进行交互
            addJavascriptInterface(this@WebViewActivity,"android")
        }
        //安卓调用js
        //点击btn可修改html上某个控件的内容
        binding.btn.setOnClickListener {
            binding.wv.loadUrl("javascript:harmonyCallJS()")
        }

        //binding.wv.addJavascriptInterface(this,"android")



    }
    @JavascriptInterface
    fun harmonyosAgree():String{
        return "nihao"
    }

}